Using Interlocked.Exchange(ref Enum, 1) to prevent re-entrancy [migrated]
Posted
by
makerofthings7
on Programmers
See other posts from Programmers
or by makerofthings7
Published on 2012-10-24T01:48:53Z
Indexed on
2012/10/24
5:25 UTC
Read the original article
Hit count: 293
What options do I have for pending work that can't acquire a lock via the following sample?
System.Threading.Interlocked.CompareExchange<TrustPointStatusEnum>
(ref tp.TrustPointStatus, TrustPointStatusEnum.NotInitalized,TrustPointStatusEnum.Loading);
Based on my research think I have the following options:
- I can use Threading.SpinWait (for very quick IO tasks) at the cost of CPU
- I can use Sleep() which has an unreliable wake up time
I'm not sure of any other option, but what I want to make sure of is that all these options work with the .NET 4 async
and await
keywords, especially if I use Task
to run them on a background thread
© Programmers or respective owner